<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-setting"></i> 系统设置 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div style="margin-bottom:10px;">
        <el-button type="primary" icon="el-icon-s-tools" v-if="threeLevelsbool.nameRole" @click="tagClick('nameRole')">人员权重</el-button>
        <el-button type="primary" icon="el-icon-s-tools" v-if="threeLevelsbool.type" @click="tagClick('type')">人员自动分配方式</el-button>
        <el-button type="warning" icon="el-icon-s-tools" v-if="threeLevelsbool.nameRole_bu" @click="tagClick('nameRole_bu')">部门权重</el-button>
        <el-button type="warning" icon="el-icon-s-tools" v-if="threeLevelsbool.type_bu" @click="tagClick('type_bu')">部门自动分配方式</el-button>
        <el-button type="danger" icon="el-icon-s-tools" v-if="threeLevelsbool.nameRole_men" @click="tagClick('nameRole_men')">门店权重</el-button>
        <el-button type="danger" icon="el-icon-s-tools" v-if="threeLevelsbool.type_men" @click="tagClick('type_men')">门店自动分配方式</el-button>
      </div>
      <root-index-quan v-if="hide.nameRole"></root-index-quan>
      <root-index-type v-if="hide.type"></root-index-type>
      <root-index-team v-if="hide.nameRole_bu"></root-index-team>
      <root-index-team-type v-if="hide.type_bu"></root-index-team-type>
      <root-index-store v-if="hide.nameRole_men"></root-index-store>
      <root-index-store-type v-if="hide.type_men"></root-index-store-type>
    </div>
  </div>
</template>

<script>
import RootIndexQuan from './RootIndexTemplate/RootIndexQuan';
import RootIndexType from './RootIndexTemplate/RootIndexType';
import RootIndexTeam from './RootIndexTemplate/RootIndexTeam';
import RootIndexTeamType from './RootIndexTemplate/RootIndexTeamType';
import RootIndexStore from './RootIndexTemplate/RootIndexStore';
import RootIndexStoreType from './RootIndexTemplate/RootIndexStoreType';
import {
  RolePermissionsQX
} from '../../../api/index';
export default {
  data() {
    return {
      threeLevelsbool: {
        nameRole: false,
        type: false,
        nameRole_bu: false,
        type_bu: false,
        nameRole_men: false,
        type_men: false
      },
      hide: {
        nameRole: false,
        type: false,
        nameRole_bu: false,
        type_bu: false,
        nameRole_men: false,
        type_men: false
      }
    };
  },
  created() {
    this.threeLevels();
  },
  components: {
    RootIndexQuan,
    RootIndexType,
    RootIndexTeam,
    RootIndexTeamType,
    RootIndexStore,
    RootIndexStoreType
  },

  methods: {
    //切换设置
    tagClick(flg) {
      for (let i in this.hide) {
        this.hide[i] = false;
      }
      switch (flg) {
        case 'nameRole': this.hide.nameRole = true; break;
        case 'type': this.hide.type = true; break;
        case 'nameRole_bu': this.hide.nameRole_bu = true; break;
        case 'type_bu': this.hide.type_bu = true; break;
        case 'nameRole_men': this.hide.nameRole_men = true; break;
        case 'type_men': this.hide.type_men = true; break;
      }
    },
    //三级权限
    threeLevels() {
      let parentRouth = this.$route.path.replace('/', '');
      RolePermissionsQX({ urlName: parentRouth }).then((res) => {
        if (res.code === 0) {
          res.buttons.forEach((item, i) => {
            switch (item.name) {
              case '人员权重':
                this.threeLevelsbool.nameRole = item.pageIsShow;
                break;
              case '人员自动分配方式':
                this.threeLevelsbool.type = item.pageIsShow;
                break;
              case '部门权重':
                this.threeLevelsbool.nameRole_bu = item.pageIsShow;
                break;
              case '部门自动分配方式':
                this.threeLevelsbool.type_bu = item.pageIsShow;
                break;
              case '门店权重':
                this.threeLevelsbool.nameRole_men = item.pageIsShow;
                break;
              case '门店自动分配方式':
                this.threeLevelsbool.type_men = item.pageIsShow;
                break;
            }
          });
        } else {
          this.$message(res.msg);
        }
      });
    }
  }
};
</script>

<style scoped>
</style>
